package com.huanshi.module.ums.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huanshi.common.CommonResult;
import com.huanshi.service.UmsMenuService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.huanshi.entity.UmsMenu;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author 幻世
 * @since 2023-09-13
 */
@RestController
@RequestMapping("/api/menu")
public class UmsMenuController {

    @Resource
    private UmsMenuService menuService;

    // 新增或者更新
    @PostMapping
    public CommonResult save(@RequestBody UmsMenu menu) {
        return CommonResult.success(menuService.saveOrUpdate(menu));
    }

    @DeleteMapping("/{id}")
    public CommonResult delete(@PathVariable Integer id) {

        return CommonResult.success(menuService.removeById(id));
    }

    @PostMapping("/del/batch")
    public CommonResult deleteBatch(@RequestBody List<Integer> ids) {

        return CommonResult.success(menuService.removeByIds(ids));
    }

    @GetMapping
    public CommonResult findAll() {
        return CommonResult.success(menuService.list());
    }

    @GetMapping("/{id}")
    public CommonResult findOne(@PathVariable Integer id) {
        return CommonResult.success(menuService.getById(id));
    }

    @GetMapping("/page")
    public CommonResult findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        QueryWrapper<UmsMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return CommonResult.success(menuService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

